package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Position;
import com.stylefeng.guns.modular.system.service.IPositionService;

/**
 * Position控制器
 *
 * @author fengshuonan
 * @Date 2019-06-11 15:28:32
 */
@Controller
@RequestMapping("/position")
public class PositionController extends BaseController {

    private String PREFIX = "/system/position/";

    @Autowired
    private IPositionService positionService;

    /**
     * 跳转到Position首页
     */
    @RequestMapping("/leave")
    public String index() {
        return PREFIX + "position.html";
    }

    /**
     * 跳转到添加Position
     */
    @RequestMapping("/position_add")
    public String positionAdd() {
        return PREFIX + "position_add.html";
    }

    /**
     * 跳转到修改Position
     */
    @RequestMapping("/position_update/{positionId}")
    public String positionUpdate(@PathVariable Integer positionId, Model model) {
        Position position = positionService.selectById(positionId);
        model.addAttribute("item",position);
        LogObjectHolder.me().set(position);
        return PREFIX + "position_edit.html";
    }

    /**
     * 获取Position列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return positionService.selectList(null);
    }

    /**
     * 新增Position
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Position position) {
        positionService.insert(position);
        return SUCCESS_TIP;
    }

    /**
     * 删除Position
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer positionId) {
        positionService.deleteById(positionId);
        return SUCCESS_TIP;
    }

    /**
     * 修改Position
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Position position) {
        positionService.updateById(position);
        return SUCCESS_TIP;
    }

    /**
     * Position详情
     */
    @RequestMapping(value = "/detail/{positionId}")
    @ResponseBody
    public Object detail(@PathVariable("positionId") Integer positionId) {
        return positionService.selectById(positionId);
    }
}
